const mongoose = require('../config/db/mongo');
const moment = require('moment');
const Schema = mongoose.Schema;
const schemaOptions = {
        versionKey: false
    }
    /**
     *
     * 小程序/ 
     * 
     *
     */
const userSchema = new Schema({

    //openid / unionID 可能和服务号一起用unionid
    openid: String,
    unionID: String,
    // 手机
    // 性别
    gender: Number,
    // 城市
    city: String,
    // 省市
    province: String,
    // 国家
    country: String,
    // 封面
    avatar: String,
    // 外号 绰号
    nickName: String,
    cellphone: String,
    lastFour: String,
    vip: Number, //0否 1是
    name:String,
    birthday:Date,
    email:String,
    referrer:{ type: mongoose.SchemaTypes.ObjectId, ref: 'user' },
    way:String,
    QRStore:String,
    QRType:String,
    

    // 真实姓名
    // name: String,
    //delete flag
    isDelete: Number, //0未删除 1已删除
    createdAt: { type: Date, default: Date.now },
    updatedAt: { type: Date },
    // 其他用户信息， 未来添加
}, schemaOptions);

// methods ====================== 提高数据库检索速度 按顺序
userSchema.index({ openid: 1 });
userSchema.index({ cellphone: 1 });


// create the model for users and expose it to our app
module.exports = mongoose.model('user', userSchema, 'user');